package com.share.device.controller;

import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.web.page.TableDataInfo;
import com.share.device.domain.CabinetType;
import com.share.device.service.CabinetTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Tag(name = "柜机类型接口")
@RestController
@RequestMapping("/cabinetType")
public class CabinetTypeController extends BaseController {
    @Autowired
    private CabinetTypeService cabinetTypeService;

    /**
     * 获取柜机类型列表
     * @param cabinetType
     * @return
     */
    @GetMapping("/list")
    @Operation(summary = "获取柜机类型列表")
    public TableDataInfo list(CabinetType cabinetType) {
        //开始分页
        startPage();
        //查询数据库中的柜机类型数据
        List<CabinetType> list = cabinetTypeService.selectCabinetTypeList(cabinetType);
        return getDataTable(list);
    }

    /**
     * 添加柜机类型
     * @param cabinetType
     * @return
     */
    @PostMapping
    @Operation(summary = "添加柜机类型")
    private AjaxResult add(@RequestBody @Validated CabinetType cabinetType) {
        return toAjax(cabinetTypeService.save(cabinetType));
    }
    /**
     * 修改柜机类型
     * @param cabinetType
     * @return
     */
    @PutMapping
    @Operation(summary = "修改柜机类型")
    private AjaxResult update(@RequestBody CabinetType cabinetType) {
        cabinetType.setUpdateTime(new Date());
        return toAjax(cabinetTypeService.updateById(cabinetType));
    }
    /**
     * 删除柜机类型
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @Operation(summary = "删除柜机类型")
    private AjaxResult delete(@PathVariable Long id) {
        return toAjax(cabinetTypeService.removeById(id));
    }
    /**
     * 获取柜机类型详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @Operation(summary = "获取柜机类型详情")
    private AjaxResult getInfo(@PathVariable Long id) {
        return success(cabinetTypeService.getById(id));
    }

    /**
     * 获取柜机类型的下拉框
     * @return
     */
    @GetMapping("/select")
    @Operation(summary = "获取柜机类型的下拉框")
    private AjaxResult select() {
        return success(cabinetTypeService.list());
    }

}
